<?php
namespace app\admin\controller;

use app\admin\model\DepartmentModel;

class Department extends Base
{
	/**
	 * [部门结构树]
	 */
	public function index(){
		if(request()->isAjax()){
            $departModel = new DepartmentModel();
            $departs = $departModel->getDepartmentList();
            $departs = arr2tree($departs);
			$exkeys = $departModel->where('pid',0)->column('id');
            return ['code'=>1,'data'=>$departs,'exkeys'=>$exkeys,'msg'=>'ok'];
        }
        return $this->fetch();
	}

	/**
	 * [添加部门]
	 */
	public function departAdd(){
        $param = input('post.');
        $depart = new DepartmentModel();
        $flag = $depart->insertDepart($param);
        return json(msg($flag['code'], $flag['data'], $flag['msg']));
    }

   	/**
	 * [编辑部门]
   	 */
    public function departEdit(){
        $param = input('post.');
        $depart = new DepartmentModel();
        $flag = $depart->editDepart($param);
        return json(msg($flag['code'], $flag['data'], $flag['msg']));
    }


    /**
	 * [删除部门]
     */
    public function departDel(){
        $id = input('param.id');
        $depart = new DepartmentModel();
        $flag = $depart->delDepart($id);
        return json(msg($flag['code'], $flag['data'], $flag['msg']));
    }
}
